﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using QuickJob.lib;
using Win32;

namespace QuickJob.forms
{
    public class TextBoxExt:AlphaBlendTextBox
    {


        public TextBoxExt():base()
        {
            ////双击--->字体
            MouseDoubleClick += TextBoxExt_MouseDoubleClick;
            Multiline = true;
            //支持中文输入法
           ImeMode = ImeMode.On;

        }

        void TextBoxExt_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            try
            {
                FontDialog fd = new FontDialog();
                DialogResult r = fd.ShowDialog();
                if (r == DialogResult.OK || r == DialogResult.Yes)
                {
                    Font = fd.Font;
                }
            }
            catch { }
        }

        protected override void OnTextChanged(EventArgs e)
        {

            Graphics g = this.CreateGraphics();

            SizeF pf = g.MeasureString(Text, Font);

            if (pf.Height > 3) Height = (int)pf.Height;
            if (pf.Width > 3) Width = (int)pf.Width;

            base.OnTextChanged(e);

            this.Invalidate();


        }
   

        #region 自定义形状
        #endregion



        #region 鼠标拖动
        bool drag = false;
        Point start;
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                drag = true;
                start = MousePosition;
            }
        }
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                drag = false;
            }
        }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (drag == true)
            {
                Point End = MousePosition;
                int x = End.X - start.X;
                int y = End.Y - start.Y;
                Location = new Point(Location.X + x, Location.Y + y);
                start = End;

            }

        }
        #endregion

    }
}
